<script setup>
import axios from 'axios'
import { ref } from 'vue'
var username = ref('')
var pwd = ref('')
var age = ref('')
var realName = ref('')
var email = ref('')
var stuNum = ref('')
var className = ref('')
var islogin = ref(false)


function register() {
    axios.post("/api/demo/reg",
        {
            username: username.value,
            email: email.value,
            pwd: pwd.value,
            age: age.value,
            realName: realName.value,
            stuNum: stuNum.value,
            className: className.value
        }).then(response => {
        localStorage.setItem('userid',response.data.data.id)
        // id 是 1874
        })
}
function login() {
    axios.post("/api/demo/login",
        {
            username: username.value,
            pwd: pwd.value
        }
    ).then(response => {
        console.log(response.data.data.id)
    })
}
function  swift() {
    islogin.value = !islogin.value
}
</script>
<template>
    <div>
        <div class="register" v-show="!islogin">
            <p>注册</p>
            username:<input type="text" name="username" v-model="username"><br>
            pwd:<input type="text" name="pwd" v-model="pwd"><br>
            age:<input type="text" name="age" v-model="age"><br>
            realName:<input type="text" name="realName" v-model="realName"><br>
            email:<input type="text" name="email" v-model="email"><br>
            stuNum:<input type="text" name="stuName" v-model="stuNum"><br>
            className:<input type="text" name="className" v-model="className"><br>
            <button @click="register">点击提交</button>
        </div>
        <div class="login" v-show="islogin">
            <p>登录</p>
            username:<input type="text" name="username" v-model="username"><br>
            pwd:<input type="text" name="pwd" v-model="pwd"><br>
            <button @click="login">点击提交</button>
        </div>
        <div @click="swift">
            点击切换登录与注册
        </div>
    </div>

</template>